home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 364_01 / intf_ca.c < prev    next >
C/C++ Source or Header  |  1992-05-24  |  19KB  |  787 lines

  1. /*
  2. HEADER:         ;
  3. TITLE:          C-ACROSS;
  4. VERSION         1.02
  5.  
  6. DESCRIPTION:   "Utility for multiple module programs. Produces
  7.       Six indexes of functions, prototypes, and globals that
  8.       enable user to 'see across' modules for use in checking
  9.       and comparison.  One of these is type of hierarchical
  10.       functions list, a listing by module of functions
  11.       and calls made FROM them; another is alphabetical list
  12.       of functions and calls made TO them. Globals listed
  13.       in schematic descriptors which record all modifiers
  14.       and qualifiers and enable checking of declarators
  15.       across modules. Creates, on request, header file
  16.       consisting of prototypes constructed from function
  17.       definitions. Can list user types #defined and some
  18.       preprocessor #defines. Full documentation in README.CA";
  19.  
  20. KEYWORDS:       Utility, Cross Reference, Deubgging;
  21. SYSTEM:         MS-DOS;
  22. FILENAME:       INTF_CA.C;
  23.  
  24. WARNINGS:      "1. Assumes function definitions conform with
  25.         ANSI standards and have prototype form. See
  26.         also "Caveats and Restrictions" in README.CA.
  27.         2. Assumes syntactically correct source files.
  28.         3. Written and tested using Microsoft QuickC.
  29.         4. Copyright retained.  See Copyright
  30.         information in README.CA.";
  31.  
  32. SEE-ALSO:      EXIT_CA.C, FUNC_CA.C, GLOB_CA.C, IFDEF_CA.C, INTF_CA.C,
  33.            LINKL_CA.C, PARSE_CA.C, TDEF_CA.C, TYPES_CA, UTIL_CA.C,
  34.            UTLG_CA.C, XRF_CA.C, README.CA,
  35.            CA.H, CA.PRJ, CA.RPT, CDECL_CA.H, KEYWORDS.H;
  36. AUTHORS:       Myron Turner;
  37. COMPILERS:     Microsoft C;
  38.  
  39. */
  40.  
  41. /***************************  C-ACROSS  ***************************
  42.                    V. 1.02
  43.                Copyright (C) Myron Turner
  44.  
  45.               333 Bartlet Ave.
  46.               Winnipeg, Manitoba
  47.               Canada R3L 0Z9
  48.               (204) 284-8387
  49.  
  50. *********************************************************************/
  51.  
  52.  
  53. #include <stdio.h>
  54. #include <string.h>
  55. #include <graph.h>
  56. #include <malloc.h>
  57. #include <stdlib.h>
  58. #include <conio.h>
  59. #include <dos.h>
  60. #include <direct.h>
  61. #include <errno.h>
  62. #define EXIT_CODES
  63. #include "ca.h"
  64. #include "ca_decl.h"
  65.  
  66. #define WHITE   0x7
  67. #define INTENSE 0x8
  68. #define HIGH_VIDEO  _settextcolor(WHITE | INTENSE)
  69. #define LOW_VIDEO   _settextcolor(WHITE)
  70.  
  71. /* general externs and globals */
  72. extern struct globals_list *globals_start;
  73. char rpt_fname[_MAX_FNAME] = "\0\0";
  74. char *CurrentMod = NULL;
  75. struct rccoord locate;
  76.  
  77. /* Globals for Command Line Options */
  78. int __Inclf_Limit = 5;
  79. char NewInclude[128]="INCLUDE=\0\0";
  80. FILE *scrn_out = (FILE *)stdout;
  81. int declare_file = 0;
  82. int user_hf_VAR = 0;
  83. int user_hf_FUNC = 0;
  84. int user_hfile_only = 0;
  85. int verbose = 0;
  86. size_t GLfpSsize = 15;
  87. static SplitNumber_rpf = 0;
  88.  
  89. int IfDefOFF = 0;
  90. int __Complex_Declarators = 1;
  91. int __Complex_Prototypes = 1;
  92.  
  93. void ini_characterset(void);
  94.  
  95. /** NOTE: Command Line and Makefile filespecs are limited to 63 characters**/
  96. /**This is set by FILENAME_MAX in STDIO.H**/
  97.  
  98. int switches_found = 0;
  99. void main(int argc, char **argv)
  100. {
  101.  struct filespec *c_file_start = NULL;
  102.  struct func *func_start;
  103.  FILE *rptfp;
  104.  char *file_string =  NULL;
  105.  int prj = 0;
  106.  
  107.  _clearscreen(0);
  108.  if (argc > 1) {
  109.     file_string = argv_cat(argc, argv);
  110.     if (*file_string == '@')   {
  111.      prj = 1;
  112.      file_string = readmakefile(file_string);
  113.      }
  114.     if (file_string)
  115.       c_file_start = extract_file_names(file_string);
  116.       else {
  117.     int c;
  118.     printf("\nMake file not found. Continue [Y/N]?\n");
  119.     c = getch();
  120.     if (c != 'y' || c != 'Y') exit(0);
  121.     }
  122.     }
  123.  if (!file_string || (!c_file_start && switches_found))
  124.                c_file_start = get_modules();
  125.  if (!c_file_start)
  126.       if (file_string && prj) exit_ca (BAD_PROJ, "");
  127.  if (!c_file_start) exit_ca (NO_FILE_STR, "");
  128.  rptfp = make_rptfile(c_file_start->path);
  129.  
  130.  ini_characterset();
  131.  
  132.  loop_through_modules (c_file_start, &func_start, rptfp);
  133.  if (declare_file) { fcloseall(); exit(0); }
  134.  
  135.  print_ll(func_start, rptfp);
  136.  
  137.  if(SplitNumber_rpf == 3)
  138.    rptfp = open_reportfile(FIRST_SPLIT);
  139.  
  140.  xrf(func_start, c_file_start, rptfp);
  141.  
  142.  if(SplitNumber_rpf == 2)
  143.    rptfp = open_reportfile(FIRST_SPLIT);
  144.  
  145.  print_calls_from(func_start, rptfp);
  146.  print_fnptrs(func_start,rptfp);
  147.  
  148.  if(SplitNumber_rpf == 3)
  149.       rptfp = open_reportfile(SECOND_SPLIT);
  150.  
  151.  print_alphab_globals(globals_start, rptfp);
  152.  
  153.  fcloseall();
  154.  
  155. }
  156.  
  157. /*lint -epu */
  158.  
  159. struct filespec *get_modules(void)
  160. {
  161.  
  162.   char *file_string, buffer[81];
  163.   size_t strL;
  164.   int ampersand;
  165.  
  166.  instructions();
  167.  
  168.  if ( !( file_string = (char *) malloc(sizeof (char) * 81 ) ) )return NULL;
  169.  
  170.  *buffer = '\0';
  171.  *file_string = '\0';
  172.  
  173.  do
  174.  {
  175.  relocate();
  176.  HIGH_VIDEO;
  177.  _outtext("C Files:  ");
  178.  LOW_VIDEO;
  179.  
  180.  fgets (buffer, 80, stdin);
  181.  if (*buffer == '\n') exit(0);
  182.  strupr( buffer );
  183.  strL = strlen(buffer);
  184.  strncat (file_string, buffer, strL - (size_t) 1);
  185.  strL = strlen(file_string);
  186.  ampersand = reallocate(file_string, strL);
  187.  
  188.   } while (ampersand);
  189.  
  190.   return ( extract_file_names(file_string));
  191.  
  192.  
  193.  }
  194.  
  195. struct filespec  *extract_file_names(char *file_string)
  196.  {
  197.   char seps[] = " +";
  198.   struct filespec  *c_file_ptr, *previous, *c_file_start = NULL;
  199.  
  200.    if ( !(
  201.     c_file_ptr = (struct filespec *)
  202.        malloc ((size_t) sizeof (struct filespec) )
  203.        ) ) return (NULL);
  204.     if (!c_file_start) c_file_start = c_file_ptr;
  205.     c_file_ptr->next = NULL;
  206.  
  207.     c_file_ptr->path = strtok( file_string, seps );     /* Find first token        */
  208.     if (!c_file_ptr->path) return (NULL);
  209.     if (c_file_ptr->path)
  210.     if(*c_file_ptr->path == '&') return (NULL);
  211.  
  212.  
  213.     while( c_file_ptr->path != NULL )
  214.     {
  215.  
  216.    previous  = c_file_ptr;
  217.  
  218.    if ( !(
  219.     c_file_ptr = (struct filespec *)
  220.        malloc ((size_t) sizeof (struct filespec) )
  221.        ) ) return (NULL);
  222.  
  223.     c_file_ptr->next = NULL;
  224.     previous->next = c_file_ptr;
  225.     c_file_ptr->path = strtok( NULL, seps );   /* Find next token         */
  226.  
  227.   }
  228.  
  229.     if (c_file_start)  return c_file_start;
  230.     return (NULL);
  231.  }
  232.  
  233.  
  234. void instructions (void)
  235. {
  236.  _clearscreen(0);
  237.  HIGH_VIDEO;
  238.  _outtext("\nInstructions:  \n");
  239.  LOW_VIDEO;
  240.  printf(
  241. "Enter C files, separated by spaces or commas; if the files need more than\n"
  242. "one line, append an & to end of line and continue on to next line (do the\n"
  243. "same for each new line needed). The \'.C\' extension is assumed. [Note: it\n"
  244. "is also assumed that each new function begins on a new line and that\n"
  245. "function declarations conform to new ANSI style.]\n\n"
  246.   );
  247.  
  248.   relocate();
  249. }
  250.  
  251.  
  252. static int reallocate(char *file_string, size_t strL)
  253. {
  254.  int count;
  255.  static int line = 1;
  256.  char *p;
  257.  
  258.  
  259.  
  260.  for (p = file_string + (int) strL - 1, count = (int) strL;
  261.                           count;   count--, p++)
  262.     if (*p != ' ') break;
  263.  
  264.  strL = count;
  265.  count--;
  266.  if (file_string[count] == '&')  {
  267.      if (file_string[count - 1] != ' ') return(0);
  268.                  }
  269.                 else return(0);
  270.  
  271.  file_string[count] = ' ';
  272.  line++;
  273.  file_string = realloc(file_string, (strL + 81) * sizeof(char));
  274.  file_string[strL] = '\0';
  275.  return (1);
  276. }
  277.  
  278. void loop_through_modules (struct filespec *top, struct func **func_start,
  279.                                 FILE *rptfp)
  280. {
  281.   char fname[_MAX_FNAME];
  282.   FILE *fp;
  283.   struct func *start = NULL, *current_func = NULL;
  284.  
  285.    if (!top) return;
  286.    if (!declare_file) print_headings(0, rptfp );
  287.  
  288.   while (top->path)
  289.   {
  290.  
  291.   do
  292.   {
  293.   strcpy(fname, top->path);
  294.   fp = open_c_file(fname, rptfp);
  295.   if (!fp)  get_new_path(top);
  296.   }
  297.   while (!fp);
  298.  
  299.   user_hfile_only =  user_hf_FUNC;
  300.   start = main_loop(fp, rptfp, fname);
  301.   CurrentMod = fname;
  302.   user_hfile_only =  user_hf_VAR;
  303.   if (!declare_file)
  304.        current_func = record_variables(fp, rptfp, current_func, &start);
  305.   fclose(fp);
  306.   top = top->next;
  307.   }
  308.  
  309.   *func_start = start;   /* func_start = start of alphabetical linked list */
  310. }
  311.  
  312.  
  313. int paginate(FILE *rptfp)
  314. {
  315.  static int line_count = 0;
  316.  static int page = 2;
  317.  char dash = '-';
  318.  
  319.  if(declare_file) return (0);
  320.  
  321.  line_count++;
  322.  if (line_count > 59)
  323.     {
  324.       fprintf(rptfp, "\f\n%38c%d-\n\n",dash, page);
  325.       line_count = 4;
  326.       heading(rptfp, rpt_fname);
  327.       page++;
  328.       return(0);
  329.